import tactu5.*;
import tactu5.Tactu5SimpleSequencer;
import controlP5.*;
import themidibus.*;





public ClientMidi clientMidi;

public Tactu5 tactu5;

public ControlP5 controlP5;

public Aggregator mainAggregator;

MainUI mainUi;

ArrayList channels = new ArrayList();

public int mainDuration = 1000;


void setup() 
{
  size(1270,350);
  background(150);
  clientMidi = new ClientMidi(this);
  controlP5 = new ControlP5(this);

  mainUi = new MainUI();

  mainAggregator = new Aggregator();
}



public void main_Duration(int v)
{
    mainDuration = v;
}

public void add_Track(int v)
{
    Channel ch = new Channel(this, channels.size());
    channels.add(ch);  
}

public void start_T5(int v)
{
   if(tactu5!=null)  tactu5.start();
}
public void stop_T5(int v)
{
   if(tactu5!=null)  tactu5.stop();
}
public void rewind_T5(int v)
{
   if(tactu5!=null)  tactu5.rewind();
}
public void update_T5(int v)
{
   if(tactu5!=null)  tactu5.updateSequencer(mainAggregator.getScore());
}
public void clean_T5(int v)
{
   if(tactu5!=null) mainAggregator.resetAll();
}










void draw() 
{
}


void noteReciver(Note n)
{
  clientMidi.send(n.getChannel(), n.getFrequency(), n.getVelocity());
}


void stop() 
{
  if(tactu5!=null) tactu5.closeSequencer();
  super.stop();
}

